
/*
  <LoadingRender v-if="loadObj.isShow" :loadObj="loadObj" @setLoadObj="e => loadObj = e"></LoadingRender>
  loadObj:{
    isShow: true,
    type: 'second', // 'percent'
    second: 10, // 如果type为second。此字段才会生效。此字段表示：loading总耗时
    percent: 0, // 此字段表表示：当前进度
    text: '加载中...',
    layout:'square', // 'circle'
  }
 */
import * as func from "./func.js"
export default {
  name: '',
  props: {
    loadObj: { type: Object, default: () => ({})},
  },
  components:{},
  data(){
    return {
      timer: null,
    }
  },
  methods:{
    ...func,
  },
  created(){
    if(this.loadObj.type == 'second') {
      this.timer = setInterval(() => {
        let {percent, second} = this.loadObj
        const descrase = (100 - percent) / 4 / Number(second)
        percent = _.range(percent + descrase, 0 ,99)
        const newLoadObj = {...this.loadObj, percent}
        this.$emit('setLoadObj', newLoadObj)
      }, 60)
    } else if(this.loadObj.type == 'percent'){

    }
  },
  mounted(){
    
  },
  beforeDestroy(){
    clearInterval(this.timer)
  }
}